#include <iostream>
#include <vector>
#include <climits> // for INT_MAX

using namespace std;

int abs(int a, int b) {
    if (a > b) return a - b;
    else return b - a;
}

int main() {
    int m, n;
    cin >> m >> n;
    int nums[m][n];
    int sum = 0;
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
            cin >> nums[i][j];
            sum += nums[i][j];
        }
    }

    vector<int> nums1(n, 0); // 统计纵
    for (int j = 0; j < n; j++) {
        for (int i = 0; i < m; i++) {
            nums1[j] += nums[i][j];
        }
    }

    vector<int> nums2(m, 0); // 统计横
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
            nums2[i] += nums[i][j];
        }
    }

    int res = INT_MAX;

    int count1 = 0;
    for (int i = 0; i < n; i++) {
        count1 += nums1[i];
        res = min(res, abs(sum - count1 - count1));
    }

    int count2 = 0;
    for (int i = 0; i < m; i++) {
        count2 += nums2[i];
        res = min(res, abs(sum - count2 - count2));
    }

    cout << res;
    return 0;
}
